package com.mjlf.nio;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.Channel;

/**
 * @ClassName BufferTest
 * @auther mjlf
 * @Date 2019/9/10 9:16
 * @Description Buffer test
 */
public class BufferTest {
    public static void main(String[] args) {
        CharBuffer charBuffer = CharBuffer.allocate(10);

        for(int i = 0; i < 8; i ++){
            charBuffer.put((char)i);
        }
        charBuffer.flip();
        charBuffer.position(2).limit(5);
        CharBuffer dup = charBuffer.duplicate();
        System.out.println(charBuffer.position());
        System.out.println(charBuffer.limit());
        System.out.println(charBuffer.capacity());

        dup.flip();
        System.out.println(dup.position());
        System.out.println(dup.limit());
        System.out.println(dup.capacity());

        CharBuffer slice = charBuffer.slice();
        System.out.println(slice.position());
        System.out.println(slice.limit());
        System.out.println(slice.capacity());

    }
}
